
/***
 * 
 * 
 */
class Component{
    drawStyle(){
        throw new Error("drawStyle")
    }
}

class UnderLineInput extends Component{
    drawStyle(){
        console.log("下划线输入框")
    }
}

class BorderInput extends Component{
    drawStyle(){
        console.log("边框输入框")
    }
}

/***
 * 实现抽象方法
 */
class AbstructDecorator extends Component{
    constructor(component){
        super()
        this.component = component
    }

    //抽象方法,java中受到保护的，只有子类才可调用
    drawColor(){
        throw new Error("drawColor")
    }
    drawStyle(){
        this.component.drawStyle()
        //可以具体装饰器调用
        this.drawColor()
    }
}
/***
 * 灰色装饰器
 */
class GrayDecorator extends AbstructDecorator{
    constructor(component){
        super(component)
    }
    //重写抽象方法
    drawColor(){
        console.log("绘制灰色边框")
    }
}


/***
 * 红色装饰器
 */
class RedDecorator extends AbstructDecorator{
    constructor(component){
        super(component)
    }
    //重写抽象方法
    drawColor(){
        console.log("绘制红色边框")
    }
}

// new GrayDecorator(new BorderInput()).drawStyle()
new RedDecorator(new BorderInput()).drawStyle()
//js没有封装特性
// new RedDecorator(new BorderInput()).drawColor()

